<!-- 模板继承 -->
{extend name="public:base" /}

<!-- 页面标题 -->
{block name="title"}Administrator{/block}

<!-- 自定义css -->
{block name="css"}{/block}

<!-- 内容区域 -->
{block name="content"}
  <div class="nav-tabs-custom">
    <ul class="nav nav-tabs">
      <li class=""><a href="{:url('admin/category/index')}">{:lang('Category')}</a></li>
      <li class="active"><a href="#">{:lang('Create')}</a></li>
      <li class="pull-right"><a href="javascript:history.back(-1);" class="text-muted"><i class="fa fa-chevron-circle-left"></i></a></li>
    </ul>
    <div class="tab-content">
      <div class="tab-pane active">
        <form role="form" id="operate">
            <div class="row">
                <div class="col-md-6">
                    <div class="box box-solid no-border">

                        <!-- /.box-header -->
                        <div class="box-body">
                            <div class="form-group">
                              <label>{:lang('Name')} <span class="text-red">*</span></label>
                              <div class="row">
                              <div class="col-md-12">
                              <input type="text" name="title" class="form-control input-sm" placeholder="">
                              </div>
                              </div>
                            </div>
                            <div class="form-group">
                              <label>{:lang('Category')} <span class="text-red">*</span></label>
                              <div class="row">
                              <div class="col-md-12">
                              <select name="pid" class="form-control input-sm">
                                <option value="0">{:lang('Not specified')}</option>
                                {volist name="category" id="vo"}
                                <option value="{$vo.id}">
                                    {eq name="vo.pid" value="0"}
                                        {$vo.title}
                                    {else/}
                                        {$vo.html} {$vo.title}
                                    {/eq}
                                </option>
                                {/volist}
                              </select>
                              </div>
                              </div>
                            </div>
                            <div class="form-group">
                              <label>{:lang('Model')}</label>
                              <div class="row">
                              <div class="col-md-12">
                              <select name="model_id" class="form-control input-sm">
                                {volist name="model" id="vo"}
                                <option value="{$vo.id}">
                                    {$vo.name}
                                </option>
                                {/volist}
                              </select>
                              </div>
                              </div>
                            </div>
                            <div class="form-group">
                              <label>{:lang('Keywords')}</label>
                              <div class="row">
                              <div class="col-md-12">
                              <input type="text" name="keywords" class="form-control input-sm" placeholder="">
                              </div>
                              </div>
                            </div>
                            <div class="form-group">
                              <label>{:lang('Description')}</label>
                              <div class="row">
                              <div class="col-md-12">
                              <textarea class="form-control input-sm" name="description" rows="3" placeholder=""></textarea>
                              </div>
                              </div>
                            </div>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <div class="box box-solid no-border">
                        <div class="box-body">
                            <div class="form-group">
                              <label>{:lang('Content')}</label>
                              <div class="row">
                              <div class="col-md-12">
                              <textarea id="editor" name="content" rows="2"></textarea>
                              </div>
                              </div>
                            </div>
                        </div>
                        <!-- /.box-body -->
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="box box-solid no-border">
                        <div class="box-body">
                            <div class="form-group">
                              <label>{:lang('Category templete')}</label>
                              <div class="row">
                              <div class="col-md-12">
                                  <select name="list_tpl" class="form-control input-sm">
                                    <option value="">--{:lang('Select')}--</option>
                                    {volist name="list_tpl" id="vo"}
                                    <option value="{$vo.name}">
                                        {$vo.path}
                                    </option>
                                    {/volist}
                                  </select>
                              </div>
                              </div>
                            </div>
                            <div class="form-group">
                              <label>{:lang('Document templete')}</label>
                              <div class="row">
                              <div class="col-md-12">
                                  <select name="detail_tpl" class="form-control input-sm">
                                    <option value="">--{:lang('Select')}--</option>
                                    {volist name="detail_tpl" id="vo"}
                                    <option value="{$vo.name}">
                                        {$vo.path}
                                    </option>
                                    {/volist}
                                  </select>
                              </div>
                              </div>
                            </div>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <div class="box box-solid no-border">
                        <div class="box-body">
                          <div class="form-group">
                            <label>{:lang('Image')}</label>
                            <div class="row">
                              <div class="col-md-12">
                                <div class="layui-upload-drag" id="image">
                                  <input type="hidden" name="image">
                                  <div class="layui-upload-list" id="preview">
                                  <p>{:lang('Upload')}</p>
                                  </div>
                                </div>
                              </div>
                            </div>
                            <p class="help-block"></p>
                          </div>

                            <div class="form-group">
                              <label>{:lang('List rows')}</label>
                              <div class="row">
                                <div class="col-md-12">
                                  <input type="text" name="list_rows" class="form-control input-sm" placeholder="">
                                </div>
                              </div>
                            </div>
                            <div class="form-group">
                              <label>{:lang('Sort')}</label>
                              <div class="row">
                                <div class="col-md-12">
                                  <input type="text" name="sort" class="form-control input-sm" placeholder="">
                                </div>
                              </div>
                              <p class="help-block"></p>
                            </div>
                            <div class="form-group">
                              <label>{:lang('Status')}</label>
                              <div class="row">
                              <div class="col-md-12">
                                <div class="radio">
                                    <label class="radio-inline">
                                        <input type="radio" name="status" value="0"> {:lang('Hidden')}
                                    </label>
                                    <label class="radio-inline">
                                        <input type="radio" name="status" value="1" checked> {:lang('Visible')}
                                    </label>
                                </div>
                              </div>
                              </div>
                            </div>
                        </div>
                        <!-- /.box-body -->
                    </div>
                </div>
            </div>
        </form>
      </div>
      <!-- /.tab-pane -->
    </div>
    <!-- /.tab-content -->
    <div class="box-footer">
        <div class="btn-group">
            <button class="btn btn-primary btn-flat" onclick="operate();" type="submit"> {:lang('Save')}</button>
        </div>
    </div>
  </div>
{/block}

<!-- 自定义js -->
{block name="js"}
<script src="__STATIC__/ueditor/ueditor.config.js"></script>
<script src="__STATIC__/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
var ue = UE.getEditor('editor', {
    toolbars: [
    ['fullscreen', 'source', 'undo', 'redo', 'selectall', '|', 'removeformat', 'formatmatch', 'autotypeset', 'cleardoc', '|', 'template', 'indent', 'horizontal','justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', 'insertcode'],
        ['fontfamily', 'fontsize', '|', 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'link', 'unlink', 'inserttable', 'deletetable', 'simpleupload', 'insertimage']
    ],
    initialFrameWidth: '100%',
    initialFrameHeight:150,
    scaleEnabled:true,
    serverUrl: '{:url("admin/ueditor/index")}',
});
</script>
<script type="text/javascript">

    layui.use('upload', function(){
      var $ = layui.jquery
      ,upload = layui.upload;
      //拖拽上传
      upload.render({
        elem: "#image"
        ,accept: 'image'
        ,multiple: false
        ,number: 1
        ,url: "{:url('admin/upload/uploadFile')}"
        ,done: function(res){
          if (res.code == 200) {
            $("[name='image']").val(res.data.url);
            $("#preview").html("<img class=\'layui-upload-img img-responsive\' src=\'"+res.data.url+"\'>");
          } else {
            swal({
              position: 'center',
              type: 'error',
              title: res.msg,
              showConfirmButton: false,
              toast:false,
              timer: 2000
            });
          }
        }
      });
    });

    function operate(){
        $.ajax({
            url:"{:url('admin/category/create')}",
            data:$("#operate").serialize(),
            type:'post',
            dataType:'json',
            success:function(xhr){
                if(xhr.code == 200){
                    swal({
                      position: 'center',
                      type: 'success',
                      title: xhr.msg,
                      showConfirmButton: false,
                      toast:false,
                      timer: 2000
                    });
                } else{
                    swal({
                      position: 'center',
                      type: 'error',
                      title: xhr.msg,
                      showConfirmButton: false,
                      toast:false,
                      timer: 2000
                    });
                }
            }
        });
    }

</script>
{/block}